<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.beaut.project.util.FlowUtility" %>
<%@ include file="/public/header.jsp"%>
<html>
	<head>
		<title>项目管理</title>
	</head>
	<script type="text/javascript">
		$(function(){
			$("#searchValue").keypress(function(e) { 
		    	// 回车键事件 
		     	if(e.which == 13) { 
		     		 doSearch();
		       	} 
		   	}); 
			$('#xm_progress_status').combobox({
				 url:'<%=contextPath%>/springMVC/xm/listXMProcessStatuc',
				 valueField:'id',
				 textField:'text',
				 onChange:function(){
						doSearch();
					}
			});
			$("#dept_id").combotree({
				url:'<%=contextPath %>/springMVC/group/listDepartment',
				method:'POST',
				animate:true,
				lines:true,
				onChange:function(){
					doSearch();
				}
			});
			jQuery("#searchValue2").keypress(function(e) { 
		    	// 回车键事件 
		     	if(e.which == 13) { 
		     		 doSearch2();
		       	} 
		   	}); 
			jQuery('#admin_id').combogrid({
				title:'立项人选择',
				mode:"remote",
				loadMsg:'正在加载数据，请稍后......',
				panelWidth:550,
				panelHeight:400,
				url:"<%=contextPath%>/springMVC/group/listPageUser",
				idField:"id",
				textField:"truename",
				rownumbers:true,
				fitColumns:true,
				columns: [[
					{field:'id',hidden:true},
					{field:'deptId',hidden:true},
					{field:'truename',title:'姓名',width:100},
					{field:'deptName',title:'所属部门',width:100},
					{field:'privName',title:'角色',width:100}
				]],
				toolbar:"#tba",
				pageSize:10,
				pageList:[10,50,100],  
				pagination:true,
				onChange:function(){
					doSearch();
				}
			});
			jQuery("#p_dept_id").combotree({
				url:'<%=contextPath %>/springMVC/group/listDepartment',
				method:'POST',
				animate:true,
				lines:true,
				onChange:function(){
					doSearch2();
				}
			});
			var xmStatus = new Array("新建","未开工", "在建", "完工", "验收", "送审", "开票" ,"结算", "关闭");
			$("#table").datagrid({
				title:"项目管理",
				iconCls:'icon-edit',
				loadMsg:'正在加载数据，请稍后......',
				url:'<%=contextPath %>/springMVC/xm/listPageXMBase?statusType=8&cancel=1',
				rownumbers:true,
				fitColumns:true,
				nowrap:false,
				idField:'id',
				frozenColumns:[[
				    {title:'主键',field:'id',hidden:true},
				]],
				columns:[[
					{title:'项目进度',field:'xm_progress_status',width:100,align:'center',formatter:function(value,rowData,rowIndex){
						return xmStatus[value];
					}},
					{title:'立项人',field:'admin_name',width:100,align:'center'},
					{title:'所属部门',field:'admin_dept',width:100,align:'center'},
					{title:'建设单位编号',field:'construct_code',width:100,align:'center'},
					{title:'项目编号',field:'xm_code',width:100,align:'center'},
					{title:'项目名称',field:'xm_name',width:200,align:'center'},
					{title:'客户',field:'customer',width:120,align:'center'},
					{title:'是否发起无合同申请',field:'contract_type',hidden:true},
					{title:'开工时间',field:'start_time',width:100,align:'center'},
					{title:'完工时间',field:'end_time',width:100,align:'center'},
					{title:'审核状态',field:'xm_flow_status',width:100,align:'center',formatter:function(value,rowData,rowIndex){
						if(value==1){
							return "审核中";
						}else if(value==2){
							return "审核不通过";
						}else if(value==3){
							return "审核通过";
						}
						return "未提交审核";
					}},
					{title:'绑定工单数量',field:'xm_gds_num',width:100,align:'center'},
			
					{title:'详情操作',field:'more',width:100,align:'center',formatter:function(value,rowData,rowIndex){
						var str="";
	                    str+= "<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-details' title='项目详情' onclick=\"javascript:viewData('"+rowData.id+"','"+rowData.xm_flow_status+"');\"/>";
	                    return str;
					}}
				]],
				toolbar:"#tb",
				pageSize:10,
				pageList : [10,50,100],  
				pagination:true,
				onLoadSuccess:function(rtJson){
					if(rtJson.rtState== '1')
					{
						$.messager.alert('提示',rtJson.rtMsrg);
					}
				}
			});
		});
		function closeXm(id){
			var rows=$('#table').datagrid('getSelections');
			$.ajax({
				type:'GET',
				url:"<%=contextPath %>/springMVC/xm/getBalancePayStatus",
				data:"id="+id,
				success:function(rtJson){
					if(rtJson.rtState == '0'){
						$.messager.alert('提示',"项目未结算支付，不能进行关闭项目！");
					}
					else{
						$.messager.confirm('确认','您确认要关闭此项目吗？',function(msg){
							if(msg){
								$.ajax({
									type:'POST',
									url:"<%=contextPath %>/springMVC/xm/closeXm",
									data:"id="+id,
									success:function(rtJson){
										if(rtJson.rtState == '0'){
											table_reload(rows.length);
										}
										else{
											warningInfo(rtJson.rtMsrg);
										}
									}
								});
							}
						});
						v
					}
				}
			});
			
		}
		function shenpi(obj,id,xm_flow_status){
	    	//flowBusinessUrl获取审批业务记录的URL(可以是个组合参数字符串),moduleFlow获取工作流程的流程名称
	      var flowBusinessUrl="<%=contextPath %>/springViews/xm/addOrEditXm.jsp?xm_id="+id+"&isShow=1&xm_flow_status="+xm_flow_status;
	      var param="flowBusinessUrl="+encodeURIComponent(flowBusinessUrl)+"&moduleFlow="+encodeURIComponent("<%=FlowUtility.XM_SHENPI%>")+"&businessId="+id+"&isShow=1";
	      $(obj).hide();
	      $.ajax({
						type:'POST',
						url:'<%=contextPath %>/springMVC/workFlow/toShenpi',
						dataType:"JSON",
						data:param,
						success:function(rtJson){
							if (rtJson.rtState == '0'){
								openDialogResize(rtJson.rtData.url,1000,800);
							}else{
								warningInfo(rtJson.rtMsrg);
							}
							$(obj).show();
						}
					});
	       
	    } 
		function showGD(gd_id,gd_content_id){
			openDialogResize('<%=contextPath%>/springViews/gd/showGd.jsp?gd_id='+gd_id+'&gd_content_id='+gd_content_id,1000, 800);
		}
		function deleteXM(xm_id){
			var rows=$('#table').datagrid('getSelections');
			$.messager.confirm('确认','您确认删除该记录信息？',function(msg){
				if(msg){
					$.ajax({
						type:'POST',
						url:"<%=contextPath %>/springMVC/xm/deleteXm",
						data:"id="+xm_id,
						success:function(rtJson){
							if(rtJson.rtState == '0'){
								table_reload(rows.length);
							}
							else{
								warningInfo(rtJson.rtMsrg);
							}
						}
					});
				}
			});
		}
		function addXM(){
			openDialogResize("<%=contextPath %>/springViews/xm/addOrEditXm.jsp?callback=rtCallBack",1000, 800);
		}
		function  editXM(id,xm_flow_status){
			openDialogResize("<%=contextPath %>/springViews/xm/addOrEditXm.jsp?xm_id="+id+"&xm_flow_status="+xm_flow_status+"&callback=rtCallBack&isShow=0",1000, 800);
	
		}
		function  viewData(id,xm_flow_status){
			openDialogResize("<%=contextPath %>/springViews/xm/addOrEditXm.jsp?xm_id="+id+"&callback=rtCallBack&isShow=1&xm_flow_status="+xm_flow_status,1000, 800);
	
		}
		function addXMGDSet(id,xm_name,xm_code){
			openDialogResize("<%=contextPath %>/springViews/xm/modifyGDSet.jsp?xm_id="+id+"&xm_name="+xm_name+"&xm_code="+xm_code+"&callback=rtCallBack",1000, 800);
			
		}
		function rtCallBack(){
			$('#table').datagrid('reload');
		}
		function addOrEditLy(id,xm_name,xm_code){
			openDialogResize("<%=contextPath %>/springViews/xm/myLvyue.jsp?xm_id="+id+"&xm_name="+xm_name+"&xm_code="+xm_code+"&callback=rtCallBack",1000, 800);

		}
		function doSearch() {
			var searchValue = $('#searchValue').val();
			var xm_progress_status = $('#xm_progress_status').combobox('getValue');
			var dept_id = $("#dept_id").combotree('getValue');
			var admin_id = jQuery("#admin_id").combotree('getValue');
			$('#table').datagrid('load', {
				searchValue : searchValue,
				dept_id : dept_id,
				xm_progress_status:xm_progress_status,
				admin_id:admin_id
			});
		}

		function doSearch2() {
			var dept_id = jQuery('#p_dept_id').combotree('getValue');
			var searchValue = jQuery('#searchValue2').val();
			jQuery('#admin_id').combogrid("grid").datagrid('load', {
				searchValue : searchValue,
				dept_id:dept_id
			});
		}
		function addContract(id){
			var rows=$('#table').datagrid('getSelections');
			$.ajax({
				type:'GET',
				url:"<%=contextPath %>/springMVC/xm/getBalancePayStatus",
				data:"id="+id,
				success:function(rtJson){
					if(rtJson.rtState == '0'){
						$.messager.alert('提示',"项目为结算支付，不能进行关闭项目！");
					}
					else{
			jQuery.messager.confirm('确认','您确定要无合同关闭吗？',function(msg){
				if(msg){
					$.ajax({
						type:'POST',
						url:"<%=contextPath %>/springMVC/xm/closeXm",
						data:"id="+id,
						success:function(rtJson){
							if(rtJson.rtState == '0'){
								table_reload(rows.length);
							}
							else{
								warningInfo(rtJson.rtMsrg);
							}
						}
					});
<%--					var flowBusinessUrl="<%=contextPath %>/springViews/xm/addOrEditXm.jsp?xm_id="+id+"&isShow=1";--%>
<%--				      var param="flowBusinessUrl="+encodeURIComponent(flowBusinessUrl)+"&moduleFlow="+encodeURIComponent("<%=FlowUtility.XM_CONTRACT_NO_SHENPI%>")+"&businessId="+id;--%>
<%--				      $.ajax({--%>
<%--									type:'POST',--%>
<%--									url:'<%=contextPath %>/springMVC/workFlow/toShenpi',--%>
<%--									dataType:"JSON",--%>
<%--									data:param,--%>
<%--									success:function(rtJson){--%>
<%--										if (rtJson.rtState == '0'){--%>
<%--											openDialogResize(rtJson.rtData.url,1000,800);--%>
<%--										}else{--%>
<%--											warningInfo(rtJson.rtMsrg);--%>
<%--										}--%>
<%--									}--%>
<%--								});--%>
				}else{
					openDialogResize("<%=contextPath %>/springViews/xm/contractManage.jsp?callback=rtCallBack",1000, 800);

				}
			});
					}
				}
				});
		}
	</script>
	<body style="height: 97%">
	<div id="table" data-options="fit:true"></div>
	<div id="tb" style="padding:3px;height:auto">
		<div style="float:left;">
		</div>
		<div align="right">
			立项人：<input type="text" id="admin_id" name="admin_id"   style="width:100px"> &nbsp;&nbsp;
			所属部门：<input  id="dept_id" name="dept_id" class="easyui-combotree">&nbsp;&nbsp; 
			项目进度：<input id="xm_progress_status" name="xm_progress_status" />&nbsp;&nbsp; 
			项目编号/名称：<input id="searchValue" name="searchValue" style="width:150px" title="建设单位编号/项目编号/名称" placeholder="建设单位编号/项目编号/名称 "  />&nbsp;&nbsp; 
			<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true" onclick="doSearch();"></a>
		</div>
	</div>
		<div id="tba" style="padding:3px;height:auto">
			<div align="right">
			             所属部门：<input  id="p_dept_id" name="p_dept_id"  style="width:150px"  class="easyui-combotree">
				查询条件：<input id="searchValue2" name="searchValue2" style="width:150px" title="用户名称或者用户真实姓名"/>
				<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true" onclick="doSearch2();"></a>
			</div>
		</div>
</body>
</html>